package com.CST.controller.zx;


import com.CST.bo.zx.ProjectAppealBO;
import com.CST.bo.zx.ProjectAppealDetailBO;
import com.CST.common.api.ResultObject;
import com.CST.entity.zx.ZxProjectAppeal;
import com.CST.service.zx.IZxProjectAppealService;
import com.CST.util.PageHelperTool;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.annotations.*;

import java.text.ParseException;
import java.util.*;

import org.springframework.beans.factory.annotation.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ly
 * @since 2023-03-23
 */
@Api(tags = {"项目申诉记录"})
@RestController
@RequestMapping("/zxProjectAppeal")

public class ZxProjectAppealController {

    @Autowired
    private IZxProjectAppealService targetService;
    @PostMapping("/saveProjectAppeal")
    @ApiOperation("新建申诉记录")
    public ResultObject saveProjectAppeal(@RequestBody ZxProjectAppeal zxProjectAppeal) {
        return targetService.saveZxProjectAppeal(zxProjectAppeal)?ResultObject.success("新建成功"):ResultObject.success("新建失败");
    }


    @PostMapping("/pageForZxProjectAppeal")
    @ApiOperation("分页显示项目申诉记录")
    public ResultObject pageForZxProjectAppeal(@RequestBody ProjectAppealBO projectAppealBO) {
        List<ZxProjectAppeal> list = targetService.queryAllAppeal(projectAppealBO);
        return ResultObject.success(PageHelperTool.excutePageInfo(list,projectAppealBO.getPageNo(), projectAppealBO.getPageSize()));
    }

    @PostMapping("/queryZxProjectAppealForDetail")
    @ApiOperation("查询项目申诉记录基本信息")
    public ResultObject queryZxProjectAppealForDetail(@RequestBody ProjectAppealDetailBO projectAppealDetailBO) throws ParseException {
        Map<String,Object> map = targetService.queryZxProjectAppealForDetail(projectAppealDetailBO);
        return ResultObject.success(map);
    }

    @PostMapping("/editZxProjectAppeal")
    @ApiOperation("修改项目申诉记录信息,修改必须要申诉的id")
    public ResultObject editZxProjectAppeal(@RequestBody ZxProjectAppeal zxProjectAppeal) {
        Boolean flag = targetService.editZxProjectAppeal(zxProjectAppeal);
        return flag?ResultObject.success("修改成功"):ResultObject.failed("修改失败");
    }

    @DeleteMapping("/deleteZxProjectAppeal/{id}")
    @ApiOperation("撤回项目申诉记录信息")
    public ResultObject deleteZxProjectAppeal(@PathVariable Long id) {
        LambdaQueryWrapper<ZxProjectAppeal> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(id!=null, ZxProjectAppeal::getId,id)
                .eq(ZxProjectAppeal::getStatus,0);
        Boolean flag = targetService.remove(lambdaQueryWrapper);
        return flag?ResultObject.success("撤回成功"):ResultObject.failed("撤回失败");
    }

/*    @GetMapping("/queryFinancialCode")
    @ApiOperation("查询财务编号")
    public ResultObject queryFinancialCode(@RequestParam(required = false) String financialCode) {
        List<String> financialCodeList = zxProjectInfoService.queryFinancialCode(financialCode);
        return ResultObject.success(financialCodeList);
    }

    @GetMapping("/queryProjectCode")
    @ApiOperation("查询项目编号")
    public ResultObject queryProjectCode(@RequestParam(required = false) String projectCode) {
        List<String> projectCodeList = zxProjectInfoService.queryProjectCode(projectCode);
        return ResultObject.success(projectCodeList);
    }

    @GetMapping("/queryProjectEasyName")
    @ApiOperation("查询项目简称")
    public ResultObject queryProjectEasyName(@RequestParam(required = false) String projectEasyName) {
        List<String> projectEasyNames = zxProjectInfoService.queryProjectEasyName(projectEasyName);
        return ResultObject.success(projectEasyNames);
    }

    @GetMapping("/queryProAllName")
    @ApiOperation("查询项目全称")
    public ResultObject queryProAllName(@RequestParam(required = false) String proAllName) {
        List<String> proAllNames = zxProjectInfoService.queryProAllName(proAllName);
        return ResultObject.success(proAllNames);
    }*/


/*    @PostMapping("/queryZxProjectBaseInfo")
    @ApiOperation("查询项目基本信息")
    public ResultObject queryZxProjectBaseInfo(@RequestBody ProjectBaseInfoBO projectBaseInfoBO) {
        List<ZxProjectBaseInfo> zxProjectBaseInfoList = zxProjectInfoService.queryZxProjectBaseInfo(projectBaseInfoBO);
        return ResultObject.success(zxProjectBaseInfoList);
    }*/

//    @GetMapping("/queryAccountCode")
//    @ApiOperation("查询科目编码")
//    public ResultObject queryAccountCode(@RequestParam(required = false) String accountCode) {
//        List<Object> accountCodes = accountInfoService.queryAccountCode(accountCode);
//        return ResultObject.success(accountCodes);
//    }
//
//    @GetMapping("/queryAccountName")
//    @ApiOperation("查询科目名称")
//    public ResultObject queryAccountName(@RequestParam(required = false) String accountName) {
//        List<Object> accountNames = accountInfoService.queryAccountName(accountName);
//        return ResultObject.success(accountNames);
//    }
//
//    @PostMapping("/queryZxProjectAppealInfo")
//    @ApiOperation("查询申诉基本信息")
//    public ResultObject queryZxProjectAppealInfo(@RequestBody ProjectAppealInfoBO projectAppealInfoBO) {
//        List<ZxProjectAppealInfo> zxProjectAppealInfoList = accountInfoService.queryZxProjectAppealInfo(projectAppealInfoBO);
//        return ResultObject.success(zxProjectAppealInfoList);
//    }
}

